package com.gong.suanfa.n2sort;

/**
 * @author GongChang
 * @version 1.0
 * @date 2021/6/7 0007 8:50
 */
public class SelectSort {

    public static void main(String[] args) {
        int[] arr = {9,8,7,6,5,4,3,2,1};

        sort(arr);

        for (int i : arr) {
            System.out.println(i);
        }
    }

    public static void sort(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            int min = i;
            int j = i+1;
            while (j <arr.length){
                if (arr[j] < arr[min]){
                    swap(arr,j,i);
                    min = j;
                }
                j++;
            }
        }
    }

    private static void swap(int[] arr, int i, int min) {
        int t = arr[i];
        arr[i] = arr[min];
        arr[min] = t;
    }
}
